# 昵称：python小白
# 座右铭：扛得住涅槃之痛，才配得上重生之美！
# 开发时间：2023/3/4 22:15



# for循环遍历容器  遍历：将容器中的数据一个一个获取出来
# names=["张三","李四","王五","赵六"]
# 直接遍历
# for name in names:
#     if name=="王五":
#         print("有这个人 王五")

# 构造索引
# for i in range(0,len(names)):
#     print(names[i])

# tuples=(67,78,56,89,76,79,98,45,65,76)
# 遍历元祖
# for tuple in tuples:
#     print(tuple)
#
# for i in range(0,len(tuples)):
#     print(tuples[i])

# 求和并获取平均分
# total=0
# for tuple in tuples:
#     total=total+tuple
# print(total/len(tuples))

# 如果用循环遍历字典，只能获取键
# dicta={"name":"zhangsan","age":18,"hobby":"play ball"}
# for x in dicta:
#     print(x)
#     print(x,dicta[x])
# seta={1,23,232,43,345,46,56}
# for s in seta:
#     print(s)

# 1.循环操作是什么？
# 2.循环的次数

# 求和问题
# 大宝买车时，贷款12万，分10年还清
totalMoney = 0  # 保存累计还款金额
for year in range(1, 11):
    totalMoney = totalMoney + 1.2
    print("第", year, "年到了!还款1.2万累计已还", round(totalMoney, 2), "万!还剩", round(12 - totalMoney, 2), "万!")

# 1-100之间所有数的和
sub = 0
for x in range(1, 101):
    sub = sub + x
    print(x)
print("1-100所有数的和是:", sub)
